package com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.controller;


import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.SmsWnsChargeCategoryDetail;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.req.SmsWnsChargeCategoryDetailReq;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.req.SmsWnsIdListReq;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.service.SmsWnsChargeCategoryDetailService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 收费类别详情表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-01-18
 */
@RestController
@SecretBody
@RequestMapping("/welcomeNewStudent/chargeCategoryDetail")
public class SmsWnsChargeCategoryDetailController {

    @Resource
    private SmsWnsChargeCategoryDetailService smsWnsChargeCategoryDetailService;

    @ApiOperation("添加收费类别详情")
    @PostMapping("/add")
    public ResponseResult addCategoryDetail(@RequestBody SmsWnsChargeCategoryDetailReq categoryDetailReq) {
        return smsWnsChargeCategoryDetailService.addCategoryDetail(categoryDetailReq);
    }

    @ApiOperation("删除收费类别详情")
    @PostMapping("/del")
    public ResponseResult delCategoryDetail(@RequestBody SmsWnsIdListReq idListReq) {
        if (idListReq.getIdList().isEmpty()) {
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        List<SmsWnsChargeCategoryDetail> detailList = smsWnsChargeCategoryDetailService.listByIds(idListReq.getIdList());
        for (SmsWnsChargeCategoryDetail categoryDetail : detailList) {
            if (!categoryDetail.getIsModified()) {
                return CommonResult.failed(CommonCodeEnum.WNS_CHARGE_CATEGORY_CAN_NOT_UPDATE_OR_DELETE);
            }
        }

        smsWnsChargeCategoryDetailService.removeByIds(idListReq.getIdList());
        return CommonResult.success();
    }

    @ApiOperation("修改收费类别详情")
    @PostMapping("/update")
    public ResponseResult updateCategoryDetail(@RequestBody SmsWnsChargeCategoryDetailReq categoryDetailReq) {
        return smsWnsChargeCategoryDetailService.updateCategoryDetail(categoryDetailReq);
    }

    @ApiOperation("收费类别详情列表")
    @GetMapping("/list")
    public ResponseResult listCategoryDetail(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                             @RequestParam(value = "searchStr", required = false) String searchStr) {
        return smsWnsChargeCategoryDetailService.listCategoryDetail(pageNum, pageSize, searchStr);
    }

    @ApiOperation("获取收费类别详情")
    @GetMapping("/detail")
    public ResponseResult categoryDetail(@RequestParam("id") String id) {
        return smsWnsChargeCategoryDetailService.categoryDetail(id);
    }


}

